﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Data;
using LeagueOfRila.Callback;
using LeagueOfRila.View;

namespace LeagueOfRila.Model
{


    public class MenuConnectionModel : BaseModel
    {
        public Player player = new Player(string.Empty);
        private string allowedKeys = "a;z;e;r;t;y;u;i;o;p;q;s;d;f;g;h;j;k;l;m;w;x;c;v;b;n;é;';è;ç;à;.;,;@;$;?;:;#;²;*;ù;%;^;£;!;§";

        public MenuConnectionView GetView()
        {
            return this.view as MenuConnectionView;
        }

        public void UpdatePseudo(string input)
        {
            if (allowedKeys.Split(';').Contains(input.ToString().ToLower()) && this.player.pseudo.Length < 17)
            {
                this.player.pseudo += input.ToString();
            }
            else if (input == "back" && this.player.pseudo.Length >= 1)
            {
                this.player.pseudo = this.player.pseudo.Substring(0, this.player.pseudo.Length - 1);
            }
        }

        public bool VerifPseudo(string pseudo)
        {
            return Services.GetConnectService(new CConnectService(this)).VerifPseudo(pseudo);
        }
        public void DisplayError()
        {

            this.GetView().error = true;
        }
    }
}
